package com.net.framework.help.json;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

/**
 * Author：xiaobin.zhang
 * Email：154722566@qq.com
 * Date：2018-01-08 14:35
 * Desc：<--处理json数据中的类型为空问题-->
 */
public class LongTypeAdapter extends TypeAdapter<Long> {
    @Override
    public void write(JsonWriter out, Long value) throws IOException {
        out.value(value);
    }

    @Override
    public Long read(JsonReader in) throws IOException {
        long i = 0;
        try {
            String str = in.nextString();
            i = Long.valueOf(str);
        } catch (Exception e) {
        }
        return i;
    }
}